import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'

Vue.use(Vuex)

const state = {
  userinfo: {}, // 登录信息
  isLogin: '', // 是否已登录
  buttonPermission: '', // 按钮权限对象
  currentTabName: '', // 当前编辑的tab
  listQueryParam: {}, // 列表查询条件
  unresetAlarmStamp: '',
  resetAlarmStamp: '',
  alarmExporting: false,
  resetAlarmExporting: false,
  orgOptions: [], //单位列表
  refreshInspectTask: false,
  resetHiddenDangerExporting: false
}

const getters = {
  isMuilUnitUser: state => {
    return state.userinfo.isMuilUnitUser == 1
  },
  userOrgId: state => {
    return state.userinfo.org.id.toString()
  },
  userOrgIds: state => {
    return state.userinfo.organizationIds.toString()
  },
  orgOptionsAll: state => {
    return [{
      organizationId: state.userinfo.organizationIds,
      shortName: '全部业主单位',
    }].concat(state.orgOptions)
  },
  userFullOrgIds: state => {
    let ids = [state.userinfo.org.id.toString()].concat(state.userinfo.organizationIds.split(','))
    return Array.from(new Set(ids)).join(',')
  },
}

export default new Vuex.Store({
  state,
  getters,
  actions,
  mutations
})
